#!/usr/bin/env bash

DAT=`date -d '-1 day' "+%Y-%m-%d"`
sysdate=` date  "+%Y-%m-%d" `

#如果有参数传入，重跑脚本时使用（06-13号跑06-09的任务时）
#$1代表执行脚本时，传入的第一个参数 $n,第n个参数
if [ $1 ]; then
  DAT=$1
fi

echo "${DAT}"


sqoop import \
         --connect jdbc:mysql://hadoop000:3306/shop?zeroDateTimeBehavior=convertToNull \
         --username root \
         --password root \
         --table mmall_order -m -1 \
         --fields-terminated-by ',' \
         --delete-target-dir \
         --target-dir "/user/hive/warehouse/bdm.db/mmall_order/day=${DAT}"

sqoop import \
     --connect jdbc:mysql://hadoop000:3306/shop?zeroDateTimeBehavior=convertToNull \
     --username root \
     --password root \
     --table mmall_order_item -m -1 \
     --fields-terminated-by ',' \
     --delete-target-dir \
     --target-dir "/user/hive/warehouse/bdm.db/mmall_order_item/day=${DAT}"

sqoop import \
     --connect jdbc:mysql://hadoop000:3306/shop?zeroDateTimeBehavior=convertToNull \
     --username root \
     --password root \
     --table mmall_shipping -m -1 \
     --fields-terminated-by ',' \
     --delete-target-dir \
     --target-dir "/user/hive/warehouse/bdm.db/mmall_shipping/day=${DAT}"